home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_2 / fifolib / fifo.doc < prev    next >
Text File  |  1992-08-24  |  11KB  |  299 lines

  1.  
  2.                 FIFO.DOC
  3.  
  4. By: Matthew Dillon
  5.             UUCP:    dillon@overload.Berkeley.CA.US
  6.  
  7.         Version 3.2
  8.  
  9.  
  10.     (1) INSTALLATION
  11.  
  12.     To Install the system you must install both FIFO-HANDLER and
  13.     FIFO.LIBRARY.
  14.  
  15.     1> lharc -r -x -a x fifo3.lzh
  16.     1> cd fifolib
  17.     1> Copy l/fifo-handler l:
  18.     1> Copy libs/fifo.library libs:
  19.  
  20.     THERE IS NO MOUNTLIST OR MOUNT FOR FIFO: ... To start the handler
  21.     and make FIFO: available to programs, you must RUN it from your
  22.     startup-sequence.  Generally the easiest way to do this is to
  23.     include the following line:
  24.  
  25.     run <nil: >nil: l:fifo-handler
  26.  
  27.     IF YOU HAVE A FIFO: ENTRY IN YOUR MOUNTLIST, PLEASE DELETE IT TO
  28.     PREVENT ACCIDENTLY TRYING TO MOUNT IT.
  29.  
  30.     (2) SIMPLE EXAMPLE TO GET YOU STARTED
  31.  
  32.     This is a simple example to get you started.  Please refer to
  33.     section (3) below for a description of the options.
  34.  
  35.     1> type fifo:r
  36.     1> run type s:startup-sequence >fifo:wmKe
  37.  
  38.     This particular examples requires that the reader be started first
  39.     (due to the 'K' flag in the writer) but also allows you to ^C the
  40.     reader (the first type command) without locking up the writer.
  41.  
  42.     (3) USAGE FOR FIFO:
  43.  
  44.     FIFO: is like PIPE: but is based on fifo.library rather than its
  45.     own implementation.  Full master/slave support exists.    Since FIFO:
  46.     uses fifo.library, programs that require non-blocking IO capability
  47.     can access one side of a FIFO: connection via the fifo.library
  48.     instead of FIFO:
  49.  
  50.     The implementation of FIFO: and fifo.library is a billion times
  51.     better than that for my original PIPE: handler.
  52.  
  53.     The primary difference with FIFO: is that it is based on a
  54.     MASTER-SLAVE connection.  Two MASTER-SLAVE connections going in
  55.     opposite directions yields a full-duplex connection.  When using
  56.     FIFO: to direct one program's output to another's input you must
  57.     explicitly specify one of the FIFO:'s to be the master and the
  58.     other the slave, as well as specify read & write flags.  The
  59.     general format for accessing the FIFO: handler is as follows:
  60.  
  61.         FIFO:<name>/<flags>
  62.  
  63.     <name>:    a valid fifo name
  64.  
  65.     name may be any combination of alpha numerics up to 64 chars long,
  66.     and is case sensitive.    FIFO: will append either "_m" or "_s" to
  67.     the name it supplies to fifo.library depending on whether master
  68.     mode or slave mode is selected.
  69.  
  70.     <flags>:    a valid combination of flags
  71.  
  72.     r   open for read.  Allows you to read from this fifo.
  73.  
  74.     w   open for write.  Allows you to write to this fifo
  75.  
  76.     rw  open for read & write (full duplex).  This opens a
  77.         full duplex connection, generally useful only in
  78.         remote-shell applications.
  79.  
  80.     c   open in cooked mode - must be specified on one side only,
  81.         usually the slave side.  Any data received by the slave
  82.         side is cooked before continuing on to the slave.  This allows
  83.         the slave side, usually a shell and/or program, to change
  84.         between cooked and raw mode with the standard SCREEN_MODE
  85.         packet.
  86.  
  87.     e   EOF mode (when combined with 'w').  When this file handle
  88.         is closed, an EOF will be sent to the other side.
  89.  
  90.         If not specified, you can cause several programs to 'append'
  91.         their output onto a single FIFO all of which is read by a
  92.         single program.  This can be useful in log-recorder
  93.         applications, for example.
  94.  
  95.         Specifying the 'e' flag generates an EOF after the last byte
  96.         of data is written to the FIFO and the writer closes it.  A
  97.         reader will read the data and then receive the EOF, generally
  98.         terminating reader operations.
  99.  
  100.     k   KEEP mode.    If a writer opens a fifo, writes data, then
  101.         closes the fifo before a reader has a chance to open the
  102.         fifo, this flag prevents the data from being lost.
  103.  
  104.         If not specified, the data will be lost.  Generally you
  105.         want to specify this flag.
  106.  
  107.     K   READER REQUIRED mode.  When specified, any Write() operation
  108.         to a fifo for which there is no reader will FAIL.  This will
  109.         prevent lockups from occuring when you use FIFO: to pipe
  110.         several processes together and then ^C the last one.
  111.  
  112.         ** This can be an important option to use to prevent hung
  113.            processes!!! **
  114.  
  115.     m   select master side (else slave).  For example, the master
  116.         side writer "mw" is paired with the slave side reader "r":
  117.  
  118.             mw   -> r
  119.             mr  <-    w
  120.             mrw <-> rw
  121.  
  122.         When operating a pipe where you have a writer into the fifo
  123.         and then a reader from the same fifo, one of the two must
  124.         be a MASTER, with the 'm' flag specified, and the other side
  125.         must be a SLAVE, with the 'm' flag NOT specified, as per
  126.         the example in section (2).
  127.  
  128.     t   tee read.  Usually specified "rt" or "mrt" depending on what
  129.         you want to monitor.  This option causes the read stream to
  130.         be a copy of available read data such that it does NOT
  131.         interfere with other readers.
  132.  
  133.         Otherwise this fifo will compete with other fifos for read
  134.         data.  For a remote shell, tee operation is not desireable
  135.         as a default but is useful to monitor the shell from an
  136.         independant program.
  137.  
  138.         see the REMCLI example below.
  139.  
  140.     s   SHELL mode, creates a separate message port for the handle,
  141.         allowing the shell & progams to find their STDERR handle.
  142.         (i.e. the open-* packet works properly).
  143.  
  144.         WARNING: use of this option increases overhead in the FIFO:
  145.         device and is generally required to be specified for the slave
  146.         side of a shell (i.e. newshell fifo:name/rwkecs)
  147.  
  148.         see the REMCLI example below.
  149.  
  150.     C   Send ^C to all (slaves or masters)
  151.     D   Send ^D to all (slaves or masters)
  152.     E   Send ^E to all (slaves or masters)
  153.     F   Send ^F to all (slaves or masters)
  154.  
  155.         You can send one or more signal to all the slaves (or masters
  156.         if 'm' is also included) using these flags.  note that it is
  157.         not necessary to open a file handle to so, specifying a
  158.         string like this:
  159.  
  160.         "FIFO:fubar/C"
  161.  
  162.         would result in sending a ^C to all fubar slaves even though
  163.         the Open() fails due to the lack of a 'r' or 'w' in the
  164.         specification.
  165.  
  166.              SEE REMCLI.C FOR EXAMPLE IMPLEMENTATION
  167.              OF COOKED MODE AND SIGNALS.
  168.  
  169.  
  170.     (4) TECHNICAL, INTERACTION BETWEEN FIFO: and FIFO.LIBRARY
  171.  
  172.                    LINKED FIFOS
  173.  
  174.     FIFO: provides a full duplex connection using TWO fifo.library FIFOS.
  175.     Openning a fifo in master mode verses slave mode determines which
  176.     names are used for reading and writing.  You should note that when
  177.     a FIFO: handle is openned for both read and write, reading from the
  178.     handle actually accesses a different physical fifo than writing to
  179.     the handle.  Openning a FIFO: for only one direction ('r' *or* 'w')
  180.     results in a half duplex connection.  It is important to properly
  181.     specify the rw modes for the fifo.
  182.  
  183.          FIFO: device             fifo.library
  184.  
  185.     Open("FIFO:junk/w", 1005);              junk_s
  186.     Open("FIFO:junk/r", 1005);              junk_m
  187.     Open("FIFO:junk/rw",1005);              junk_s (w), junk_m (r)
  188.  
  189.     Open("FIFO:junk/wm", 1005);             junk_m
  190.     Open("FIFO:junk/rm", 1005);             junk_s
  191.     Open("FIFO:junk/rwm", 1005);            junk_m (w), junk_s (r)
  192.  
  193.     (5) REMOTE SHELL APPLICATIONS
  194.  
  195.     It is extremely easy to set up a fifo to interface a program with a
  196.     remote shell.  The FIFO: fully supports remote shells including the
  197.     ability to propogate ^C through ^F and handle stderr ("*").
  198.  
  199.     Not only that, but programs which need to be able to access the
  200.     master side of a shell in a non-blocking fashion may access the
  201.     master side directly through FIFO.LIBRARY calls.  See FIFOLIB.DOC
  202.     for the function call list, see REMCLI.C for a working example.
  203.  
  204.     1> NewShell FIFO:name/rwkecs
  205.     1> run remcli name
  206.  
  207.     Generally the shell is run off the slave side and the controlling
  208.     program is run off the master side.  The side that runs the shell
  209.     MUST specify the 's' option, as shown above.  Here is a description
  210.     of the flags used in the NewShell line:
  211.  
  212.     rw  full duplex connection.  shell 'reads' from the master and
  213.         'writes' results back to the msater.
  214.  
  215.     k   if slave side is started up first, as in the above example, any
  216.         writes it does will NOT be lost.  Not really required since the
  217.         slave side shell does not endcli itself.
  218.  
  219.     e   when slave side closes the handle, an EOF will be sent to
  220.         the master side.
  221.  
  222.     c   run slave side in COOKED mode.  FIFO: will do command line
  223.         editing on any data sent to the slave side.  You do not specify
  224.         COOKED mode for the master side.  I repeat, do NOT specify
  225.         cooked mode for the master side.  (you can't in the above
  226.         example since the master is the 'remcli' program.
  227.  
  228.         note that in COOKED mode, FIFO: echo's characters received on
  229.         the slave side back to the master, just like the console
  230.         device.
  231.  
  232.     s   SHELL support, required on the slave specification when run
  233.         from NewShell, causes the handle to get its own message port.
  234.         (required to support Open("*", ...);
  235.  
  236.     NOTE:  YOU CAN RUN 'remcli name' MULTIPLE TIMES SIMULTANIOUSLY
  237.     USING THE SAME FIFO NAME.  All remcli's talking to the same shell
  238.     will get all output from the shell and additionally be able to
  239.     issue commands.  This can be extremely useful as a monitoring tool.
  240.  
  241.         1> run remcli name
  242.         1> run remcli name
  243.  
  244.     You can also capture all shell interaction with this:
  245.  
  246.         1> copy FIFO:name/rmt t:capture
  247.  
  248.     The 't' (TEE) specification is required to ensure you do not screw
  249.     up any other readers.  There is no limit on the number of 'readers'
  250.     monitoring a named fifo.  The RemCLI program uses the fifo.library
  251.     to access the master side and thus TEEs automatically.
  252.  
  253.     If RemCLI tries to talk to a fifo that does not exist, it will
  254.     'freeze' until the slave side does exist.  Meaning you can run
  255.     RemCLI before you start up the shell.
  256.  
  257.     CLOSING THE REMCLI WINDOW DOES NOT END THE SHELL.  You must type
  258.     'endcli' or 'endshell' to cause it to exit.  On the otherhand,
  259.     closing the remcli window and then reopenning will yield the
  260.     previous shell (which never exited).
  261.  
  262.  
  263.                 PIPEING
  264.  
  265.     You can use the FIFO: device to pipe output from one program to the
  266.     input of another.  Note that you want to be sure to use the 'k' flag
  267.     in case the program generating the output generates only a little (and
  268.     is able to exit before you have a chance to start the reader).  You
  269.     also want to use the 'e' (EOF) option or the reader will not receive
  270.     an EOF, and you must make one side a master.
  271.  
  272.     1> type s:startup-sequence >FIFO:xx/wkme
  273.     1> type FIFO:xx/r
  274.  
  275.     If you do not specify the 'e' EOF option then you can run multiple
  276.     program's output through the pipe sequentially, specifying the eof
  277.     option only for the last one.
  278.  
  279.     WARNING:    If you ^C the reader before it gets the EOF and exits
  280.     on its own, and if the writer is still writing, the writer will
  281.     freeze up when the fifo becomes full (requiring a reader to unfreeze
  282.     it).  Additionally, if the 'k' option is not used, even if the writer
  283.     does not freeze up there may be unwanted data left in the fifo even
  284.     though nobody is referencing it.
  285.  
  286.     To safely recover from a broken reader, the program controlling the
  287.     pipe must do the following steps:
  288.  
  289.     (1) break the writer if it has not exited (but it may be frozen,
  290.         so...)
  291.  
  292.     (2) open a reader /r and a writer /wme, then immediately close
  293.         the writer.
  294.  
  295.     (3) read from the reader until EOF.  Even if the original writer
  296.         had already exited, the fact that you open and close a dummy
  297.         one will regenerate the EOF.
  298.  
  299.